package com.qdsg.ysg.doctor.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qdsg.ysg.doctor.R;
import com.qdsg.ysg.doctor.nurse.activity.AtyWaitAccept;
import com.qdsg.ysg.doctor.ui.widget.FlowAllLayoutManager;
import com.qdsg.ysg.doctor.ui.widget.SpaceItemDecoration;
import com.rest.response.DocOrderListVO;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Description
 * Created by lbj on 2022/4/9 9:56
 */
public class WaitOrderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private Context mContext;
    private Boolean isFromHome = true;
    private List<DocOrderListVO.AcceptOrderList> mList;
    private OnItemClickLitener mOnItemClickLitener;


    public WaitOrderAdapter(Context mContext, List<DocOrderListVO.AcceptOrderList> checkList) {
        this.mContext = mContext;
        this.mList = checkList;
    }

    @NotNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        Context context = parent.getContext();
        View view = LayoutInflater.from( context )
                .inflate( R.layout.item_nurse_order, parent, false );
        return new ViewHolder( view );
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NotNull RecyclerView.ViewHolder holder, final int position) {
        final ViewHolder mHolder = (ViewHolder) holder;
        mHolder.tvSure.setVisibility( View.GONE );
        DocOrderListVO.AcceptOrderList acceptOrderList = mList.get( position );
        mHolder.tvPersonName.setText( "预约人：" + acceptOrderList.name );
        mHolder.tvPersonSex.setText( acceptOrderList.sex );
        mHolder.tvPersonAge.setText( acceptOrderList.patientAge + "岁" );
        mHolder.tvPersonAddress.setText( "地址：" + acceptOrderList.adress );
        mHolder.tvPersonTime.setText( "时间：" + acceptOrderList.appointmentTime );
        List<String> checkList = new ArrayList<>();
        checkList.clear();
        checkList.add( acceptOrderList.title );
        FlowAllLayoutManager flowLayoutManager = new FlowAllLayoutManager();
//        if (mHolder.rvCheckItems.getItemDecorationCount() == 0) {
//            mHolder.rvCheckItems.addItemDecoration( new SpaceItemDecoration( dp2px() ) );
//        }
        mHolder.rvCheckItems.setLayoutManager( flowLayoutManager );
        AdapterFlowList adapterFlow = new AdapterFlowList( mContext, checkList );
        mHolder.rvCheckItems.setAdapter( adapterFlow );

        holder.itemView.setOnClickListener( v -> {
            Intent intent = new Intent( mContext, AtyWaitAccept.class );
            intent.putExtra( "appointmentId", mList.get( position ).id );
            intent.putExtra( "docAppointmentId", mList.get( position ).docAppointmentId );
            mContext.startActivity( intent );
        } );

        mHolder.tvSure.setOnClickListener( v -> {
            if (mOnItemClickLitener != null) {
                mOnItemClickLitener.onItemClick( position );
            }
        } );


    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public interface OnItemClickLitener {
        void onItemClick(int position);
    }


    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_person_name)
        TextView tvPersonName;
        @BindView(R.id.tv_person_sex)
        TextView tvPersonSex;
        @BindView(R.id.tv_person_age)
        TextView tvPersonAge;
        @BindView(R.id.tv_order_status)
        TextView tvOrderStatus;
        @BindView(R.id.tv_person_address)
        TextView tvPersonAddress;
        @BindView(R.id.tv_person_time)
        TextView tvPersonTime;
        @BindView(R.id.rv_check_items)
        RecyclerView rvCheckItems;
        @BindView(R.id.tv_cancel_reason)
        TextView tvCancelReason;
        @BindView(R.id.tv_sure)
        TextView tvSure;

        public ViewHolder(View itemView) {
            super( itemView );
            ButterKnife.bind( this, itemView );
        }
    }


}
